/**
 * 
 */
package com.chinaums.cfps.apps.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.chinaums.cfps.apps.listener.AbstractCfpsMQMessageListener;
import com.chinaums.ibmmq.MQRecv;

/**
 * 接收处理器模板
 * @author 磊
 *
 */
public class CfpsRecvMQAppModel {
	/**
	 * 日志对象.
	 */
	private final static Logger LOGGER = LoggerFactory.getLogger(CfpsRecvMQAppModel.class);
	/**
	 * MQ 接收.
	 */
	private MQRecv mqRecv;
	/**
	 * 监听，主要业务处理
	 */
	private AbstractCfpsMQMessageListener mqMessageListener;
	/**
	 * 队列构建器.
	 */
	private CfpsMQFactory factory;
	/**名称*/
	private String name;
	/**
	 * 构造器.
	 * @param name 名称.
	 */
	public CfpsRecvMQAppModel(String name){
		this.name = name;
	}
	/**
	 * 初始化
	 */
	public void init(){
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.name+"开始初始化");
		}
		mqRecv = new MQRecv(factory.create(), null);
		mqRecv.setMqMessageListener(mqMessageListener);
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.name+"初始化完成.");
		}
	}
	/**
	 * 启动
	 */
	public void start(){
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.name+"开始启动.");
		}
		mqRecv.startMessageListener();
		this.mqMessageListener.isOk = true;
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.name+"启动完成.");
		}
	}
	/**
	 * 停止
	 */
	public void stop(){
		mqRecv.stopMessageListener();
		if(LOGGER.isInfoEnabled()){
			LOGGER.info(this.name+"停止.");
		}
		this.mqMessageListener.stopEvent();
		this.mqMessageListener.isOk = false;
	}
	public AbstractCfpsMQMessageListener getMqMessageListener() {
		return mqMessageListener;
	}
	public void setMqMessageListener(AbstractCfpsMQMessageListener mqMessageListener) {
		this.mqMessageListener = mqMessageListener;
	}
	public CfpsMQFactory getFactory() {
		return factory;
	}
	public void setFactory(CfpsMQFactory factory) {
		this.factory = factory;
	}
	
}
